/*
 * .java
 *
 * Created on 4 de mayo de 2008, 12:45 PM
 */
package org.contabilidad.tesorerosauxiliares.registros;

import org.mybeans.Sesion;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import org.menu.MenuTesorerosAuxiliares;
import org.mybeans.TesorerosAuxiliaresBeans;
import org.jdesktop.swingx.autocomplete.*;
import org.tesorerosauxiliares.busquedas.TesorerosAuxiliaresBusquedaFrame;

/**
 *
 * @author avbravo
 */
public class TesorerosAuxiliaresRegistrosFrame extends javax.swing.JFrame {

    Sesion sesion;
    TesorerosAuxiliaresBeans tesorerosAuxiliaresBeans;
    MenuTesorerosAuxiliares menuTesorerosAuxiliares;
    boolean focoTesoreroAuxiliar = false;

    /**
     * Creates new form
     */
    public TesorerosAuxiliaresRegistrosFrame() {
        initComponents();
        sesion = new Sesion();
        tesorerosAuxiliaresBeans = new TesorerosAuxiliaresBeans();
        menuTesorerosAuxiliares = new MenuTesorerosAuxiliares();
        CargarCorregimientos(sesion.getIdmunicipio(), true);
        // CargarCorregimientos("", false);
        CargarProvincias();
        // CargarMunicipios();
        AutoCompleteDecorator.decorate(this.jComboBoxCorregimiento);
        AutoCompleteDecorator.decorate(this.jComboBoxCorregimientoVive);
        AutoCompleteDecorator.decorate(this.jComboBoxMunicipioVive);
        AutoCompleteDecorator.decorate(this.jComboBoxProvincia);
        menuTesorerosAuxiliares.VerificarPrivilegios();
        /*
         * Fondo
         */

         
         
         

         
         
        /*
         * fondo
         */
        jButtonGuardar.setEnabled(false);
        jButtonEliminar.setEnabled(false);
        jButtonActualizar.setEnabled(false);
        if (sesion.getCedulaTesoreroAuxiliar() == null || sesion.getCedulaTesoreroAuxiliar().equals("")) {
        } else {
            jTextFieldCedula.setText(sesion.getCedulaTesoreroAuxiliar());
            ValidarCedula();
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldCedula = new javax.swing.JTextField();
        jTextFieldTesoreroAuxiliar = new javax.swing.JTextField();
        jTextFieldSeguroSocial = new javax.swing.JTextField();
        jTextFieldOcupacion = new javax.swing.JTextField();
        jTextFieldNacionalidad = new javax.swing.JTextField();
        jComboBoxCorregimiento = new javax.swing.JComboBox();
        jTextFieldDomicilio = new javax.swing.JTextField();
        jTextFieldCasa = new javax.swing.JTextField();
        jTextFieldTelefono = new javax.swing.JTextField();
        jTextFieldApartado = new javax.swing.JTextField();
        jButtonActualizar = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jButtonLimpiar = new javax.swing.JButton();
        jButtonBuscarTesorerosAuxiliares = new javax.swing.JButton();
        jButtonEliminar = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldEmail = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jComboBoxMunicipioVive = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jComboBoxCorregimientoVive = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObservacion = new javax.swing.JTextArea();
        jButtonGuardar = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jComboBoxProvincia = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Registros de Tesoreros Municipales");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
         

        jLabel1.setText("Cedula");

        jLabel2.setText("Tesorero");

        jLabel3.setText("Seguro Social");

        jLabel4.setText("Ocupacion");

        jLabel5.setText("Nacionalidad");

        jLabel6.setText("Corregimiento");

        jLabel7.setText("Domicilio");

        jLabel8.setText("Casa");

        jLabel9.setText("Telefono");

        jLabel10.setText("Apartado");

        jTextFieldCedula.setColumns(35);
        jTextFieldCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCedulaActionPerformed(evt);
            }
        });

        jTextFieldTesoreroAuxiliar.setColumns(70);

        jTextFieldNacionalidad.setText("Panama");

        jButtonActualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/update.jpeg"))); // NOI18N
        jButtonActualizar.setToolTipText("Actualizar");
        jButtonActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonActualizarActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jButtonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/escoba.png"))); // NOI18N
        jButtonLimpiar.setToolTipText("Limpiar");
        jButtonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpiarActionPerformed(evt);
            }
        });

        jButtonBuscarTesorerosAuxiliares.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscarTesorerosAuxiliares.setToolTipText("Buscar ");
        jButtonBuscarTesorerosAuxiliares.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarTesorerosAuxiliaresActionPerformed(evt);
            }
        });

        jButtonEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/delete.png"))); // NOI18N
        jButtonEliminar.setToolTipText("Eliminar");
        jButtonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarActionPerformed(evt);
            }
        });

        jLabel11.setText("Email");

        jLabel12.setText("Municipio Vive");

        jComboBoxMunicipioVive.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxMunicipioViveItemStateChanged(evt);
            }
        });
        jComboBoxMunicipioVive.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxMunicipioViveActionPerformed(evt);
            }
        });
        jComboBoxMunicipioVive.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jComboBoxMunicipioViveKeyReleased(evt);
            }
        });

        jLabel13.setText("Corregimiento Vive");

        jLabel14.setText("Observacion");

        jTextAreaObservacion.setColumns(20);
        jTextAreaObservacion.setRows(5);
        jScrollPane1.setViewportView(jTextAreaObservacion);

        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonGuardar.setToolTipText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jLabel15.setText("Provincia");

        jComboBoxProvincia.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxProvinciaItemStateChanged(evt);
            }
        });
        jComboBoxProvincia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxProvinciaActionPerformed(evt);
            }
        });
        jComboBoxProvincia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jComboBoxProvinciaKeyReleased(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/new.jpeg"))); // NOI18N
        jButton1.setToolTipText("Nuevo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(58, 58, 58)
                                .addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonBuscarTesorerosAuxiliares, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(71, 71, 71)
                                .addComponent(jTextFieldCasa, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel9)
                                .addGap(67, 67, 67)
                                .addComponent(jTextFieldTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldApartado, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(67, 67, 67)
                                .addComponent(jTextFieldEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldTesoreroAuxiliar, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldSeguroSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(41, 41, 41))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(246, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxCorregimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(251, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(45, 45, 45)
                        .addComponent(jTextFieldDomicilio, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(132, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jButtonActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(85, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxMunicipioVive, 0, 461, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addGap(3, 3, 3)
                                .addComponent(jComboBoxCorregimientoVive, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(41, 41, 41))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(42, 42, 42)
                        .addComponent(jComboBoxProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(259, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextFieldCedula))
                        .addComponent(jButtonBuscarTesorerosAuxiliares, javax.swing.GroupLayout.PREFERRED_SIZE, 27, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(1, 1, 1)))
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldTesoreroAuxiliar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldSeguroSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jComboBoxCorregimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldDomicilio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldCasa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9)
                        .addComponent(jLabel8))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldApartado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jComboBoxMunicipioVive, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jComboBoxCorregimientoVive, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jComboBoxMunicipioViveItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxMunicipioViveItemStateChanged
}//GEN-LAST:event_jComboBoxMunicipioViveItemStateChanged

private void jComboBoxMunicipioViveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxMunicipioViveActionPerformed

    String municipio = (String) jComboBoxMunicipioVive.getSelectedItem();
    String idMunicipio = BuscarMunicipios(municipio);
    CargarCorregimientos(idMunicipio, false);
}//GEN-LAST:event_jComboBoxMunicipioViveActionPerformed

private void jComboBoxMunicipioViveKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jComboBoxMunicipioViveKeyReleased
}//GEN-LAST:event_jComboBoxMunicipioViveKeyReleased

private void jButtonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpiarActionPerformed

    Limpiar();
}//GEN-LAST:event_jButtonLimpiarActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jButtonActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonActualizarActionPerformed

    try {
        if (CargarBeans() == false) {
            return;
        }

        tesorerosAuxiliaresBeans.Actualizar();
        jButtonEliminar.setEnabled(false);
        jButtonActualizar.setEnabled(false);
        if (menuTesorerosAuxiliares.isBjMenuItemTesorerosAuxiliaresActualizar() == true) {
            jButtonActualizar.setEnabled(true);
        }
        if (menuTesorerosAuxiliares.isBjMenuItemTesorerosAuxiliaresEliminar() == true) {
            jButtonEliminar.setEnabled(true);
        }
    } catch (Exception ex) {

        JOptionPane.showMessageDialog(this, "Boton Actualizar()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonActualizarActionPerformed

    private boolean CargarBeans() {
        try {
            String cedula = this.jTextFieldCedula.getText();
            if (cedula == null || cedula.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese la cedula del tesorero auxiliar", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldCedula.requestFocus();
                return false;
            }

            String TesoreroAuxiliar = this.jTextFieldTesoreroAuxiliar.getText();
            if (TesoreroAuxiliar == null || TesoreroAuxiliar.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el nombre del tesorero auxiliar", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldTesoreroAuxiliar.requestFocus();
                return false;
            }
            String IdSeguroSocial = this.jTextFieldSeguroSocial.getText();
            if (IdSeguroSocial == null) {
                IdSeguroSocial = "";
            }
            String Ocupacion = this.jTextFieldOcupacion.getText();
            if (Ocupacion == null || Ocupacion.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese la ocupacion del tesorero auxiliar", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldOcupacion.requestFocus();
                return false;
            }
            String Nacionalidad = this.jTextFieldNacionalidad.getText();
            if (Nacionalidad == null || Nacionalidad.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese la nacionalidad", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldNacionalidad.requestFocus();
                return false;
            }

            String Corregimiento = (String) this.jComboBoxCorregimiento.getSelectedItem();
            if (Corregimiento == null || Corregimiento.equals("")) {
                JOptionPane.showMessageDialog(this, "seleccione un corregimiento", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }

            String IdCorregimiento = BuscarCorregimientos(sesion.getIdmunicipio(), Corregimiento);
            String Domicilio = this.jTextFieldDomicilio.getText();
            if (Domicilio == null || Domicilio.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el domicilio", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldDomicilio.requestFocus();
                return false;
            }

            String Casa = this.jTextFieldCasa.getText();
            String Telefono = this.jTextFieldTelefono.getText();
            String ApartadoPostal = this.jTextFieldApartado.getText();
            String Email = this.jTextFieldEmail.getText();
            String Observacion = this.jTextAreaObservacion.getText();


            String MunicipioVive = (String) this.jComboBoxMunicipioVive.getSelectedItem();
            if (MunicipioVive == null || MunicipioVive.equals("")) {
                JOptionPane.showMessageDialog(this, "seleccione el municipio donde vive", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }
            String IdMunicipioVive = BuscarMunicipios(MunicipioVive);

            String CorregimientoVive = (String) this.jComboBoxCorregimientoVive.getSelectedItem();
            if (CorregimientoVive == null || CorregimientoVive.equals("")) {
                JOptionPane.showMessageDialog(this, "seleccione el corregimiento donde vive", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }

            String IdCorregimientoVive = BuscarCorregimientos(IdMunicipioVive, CorregimientoVive);

            tesorerosAuxiliaresBeans.setCedula(cedula);
            tesorerosAuxiliaresBeans.setTesoreroAuxiliar(TesoreroAuxiliar);
            tesorerosAuxiliaresBeans.setIdSeguroSocial(IdSeguroSocial);
            tesorerosAuxiliaresBeans.setOcupacion(Ocupacion);
            tesorerosAuxiliaresBeans.setNacionalidad(Nacionalidad);
            tesorerosAuxiliaresBeans.setIdMunicipio(sesion.getIdmunicipio());
            tesorerosAuxiliaresBeans.setIdCorregimiento(IdCorregimiento);
            tesorerosAuxiliaresBeans.setDomicilio(Domicilio);
            tesorerosAuxiliaresBeans.setCasa(Casa);
            tesorerosAuxiliaresBeans.setTelefono(Telefono);
            tesorerosAuxiliaresBeans.setApartadoPostal(ApartadoPostal);
            tesorerosAuxiliaresBeans.setEmail(Email);
            tesorerosAuxiliaresBeans.setObservacion(Observacion);
            tesorerosAuxiliaresBeans.setIdMunicipioVive(IdMunicipioVive);
            tesorerosAuxiliaresBeans.setIdCorregimientoVive(IdCorregimientoVive);
            return true;
        } catch (Exception ex) {

            JOptionPane.showMessageDialog(this, "CargarBeans()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }
private void jButtonBuscarTesorerosAuxiliaresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarTesorerosAuxiliaresActionPerformed
    TesorerosAuxiliaresBusquedaFrame tesorerosAuxiliaresBusquedaFrame = new TesorerosAuxiliaresBusquedaFrame();
    tesorerosAuxiliaresBusquedaFrame.setLocationRelativeTo(null);
    tesorerosAuxiliaresBusquedaFrame.setVisible(true);


    focoTesoreroAuxiliar = true;
}//GEN-LAST:event_jButtonBuscarTesorerosAuxiliaresActionPerformed

private void jTextFieldCedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCedulaActionPerformed

    ValidarCedula();

}//GEN-LAST:event_jTextFieldCedulaActionPerformed

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
    try {

        if (focoTesoreroAuxiliar) {
            CargarTesoreroAuxiliar();
        }

        focoTesoreroAuxiliar = false;
    } catch (Exception ex) {
        sesion.MostrarMensajeError("Error ", "Clase: TesorerosAuxiliaresRegistrosFrame.java\nBoton Actualizar Impuestos()\n " + ex.getMessage().toString());
    }
}//GEN-LAST:event_formWindowGainedFocus

private void jButtonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEliminarActionPerformed

    try {
        String Cedula = this.jTextFieldCedula.getText();
        if (Cedula == null || Cedula.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese la cedula ", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldCedula.requestFocus();
            return;
        }

        String tesoreroAuxiliar = this.jTextFieldTesoreroAuxiliar.getText();
        if (tesoreroAuxiliar == null || tesoreroAuxiliar.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el tesorero auxiliar", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldCedula.requestFocus();
            return;
        }

        tesorerosAuxiliaresBeans.setCedula(Cedula);
        if (tesorerosAuxiliaresBeans.Eliminar() == true) {
            Limpiar();
        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Boton Eliminar\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonEliminarActionPerformed

private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed


    try {
        if (CargarBeans()) {
            tesorerosAuxiliaresBeans.Crear();
        }


    } catch (Exception ex) {
        System.out.println("Error" + ex);
        JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonGuardarActionPerformed

private void jComboBoxProvinciaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxProvinciaItemStateChanged
    // TODO add your handling code here:
}//GEN-LAST:event_jComboBoxProvinciaItemStateChanged

private void jComboBoxProvinciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxProvinciaActionPerformed
    // TODO add your handling code here:
    String provincia = (String) jComboBoxProvincia.getSelectedItem();
    String idProvincia = BuscarProvincias(provincia);
    CargarMunicipios(idProvincia, false);
}//GEN-LAST:event_jComboBoxProvinciaActionPerformed

private void jComboBoxProvinciaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jComboBoxProvinciaKeyReleased
    // TODO add your handling code here:
}//GEN-LAST:event_jComboBoxProvinciaKeyReleased

    @SuppressWarnings("static-access")
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        try {
            String cedula = this.jTextFieldCedula.getText();
            sesion.setCedulaTesoreroAuxiliar(this.jTextFieldCedula.getText());
            if (tesorerosAuxiliaresBeans.ConsultarSinMensaje(cedula) == true) {
                CargarTesoreroAuxiliar();
            } else {
                Limpiar();
                if (menuTesorerosAuxiliares.isBjMenuItemTesorerosAuxiliaresAgregar() == true) {
                    jButtonGuardar.setEnabled(true);

                } else {
                    //     System.out.println("ax no tiene privilegios para agregar");
                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jButton1ActionPerformed

    private void ValidarCedula() {
        try {
            String cedula = this.jTextFieldCedula.getText();
            sesion.setCedulaTesoreroAuxiliar(this.jTextFieldCedula.getText());
            if (tesorerosAuxiliaresBeans.Consultar(cedula) == true) {
                CargarTesoreroAuxiliar();
            } else {
                Limpiar();
                if (menuTesorerosAuxiliares.isBjMenuItemTesorerosAuxiliaresAgregar() == true) {
                    jButtonGuardar.setEnabled(true);
                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TesorerosAuxiliaresRegistrosFrame().setVisible(true);
            }
        });
    }

    private String BuscarCorregimientos(String idMunicipio, String corregimiento) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return "";
            }
            String sqlquery = "select * from corregimients where idmunicipio = ? and corregimiento =?";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, idMunicipio);
            psquery.setString(2, corregimiento);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();

            if (x == 0) {
                JOptionPane.showMessageDialog(this, "no existe un corregimiento con ese nombre", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

                return "";
            }

            return rs.getString("idcorregimiento");


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando Corregimientos" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        return "";
    }

    private String BuscarCorregimientosCodigo(String idMunicipio, String corregimiento) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return "";
            }
            String sqlquery = "select * from corregimients where idmunicipio = ? and idcorregimiento =?";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, idMunicipio);
            psquery.setString(2, corregimiento);
            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();

            if (x == 0) {
                JOptionPane.showMessageDialog(this, "no existe un corregimiento con ese codigo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

                return "";
            }
            return rs.getString("corregimiento");


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando Corregimientos" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        return "";
    }

    private String BuscarMunicipios(String municipio) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return "";
            }

            String sqlquery = "select * from municipies where municipio = ? ";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, municipio);

            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();

            if (x == 0) {
                //           JOptionPane.showMessageDialog(this, "no existe un municipio ese nombre", "Mensaje", JOptionPane.INFORMATION_MESSAGE);

                return "";
            }

            return rs.getString("idmunicipio");


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando Corregimientos" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        return "";
    }

    public void CargarCorregimientos(String idMunicipio, boolean comboCorregimientoActual) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            PreparedStatement psquery;
            if (idMunicipio.equals("")) {
                //cuando se quiere mostrar todos los corregimientos
                String sqlquery = "select idcorregimiento, corregimiento  from corregimients ";
                psquery = sesion.con.prepareStatement(sqlquery);

            } else {
                String sqlquery = "select idcorregimiento, corregimiento  from corregimients where idmunicipio = ?";
                psquery = sesion.con.prepareStatement(sqlquery);
                psquery.setString(1, idMunicipio);
            }
            ResultSet rs = psquery.executeQuery();
            if (comboCorregimientoActual == true) {
                jComboBoxCorregimiento.removeAllItems();
            } else {
                jComboBoxCorregimientoVive.removeAllItems();
            }


            int count = 0;
            while (rs.next()) {
                String corregimiento = rs.getString("corregimiento");
                if (comboCorregimientoActual == true) {
                    jComboBoxCorregimiento.insertItemAt(corregimiento, count);
                } else {
                    jComboBoxCorregimientoVive.insertItemAt(corregimiento, count);
                }

                count++;
            }
            if (comboCorregimientoActual == true) {
                if (count != 0) {
                    jComboBoxCorregimiento.setSelectedIndex(0);
                }
            } else {
                if (count != 0) {
                    jComboBoxCorregimientoVive.setSelectedIndex(0);
                }
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando Corregimientos" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void CargarMunicipios() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select idmunicipio, municipio  from municipies order by municipio";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxMunicipioVive.removeAllItems();
            int count = 0;
            while (rs.next()) {
                String municipio = rs.getString("municipio");
                jComboBoxMunicipioVive.insertItemAt(municipio, count);

                count++;
            }
            if (count != 0) {
                jComboBoxMunicipioVive.setSelectedItem(sesion.getMunicipio());
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando Corregimientos" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void Limpiar() {
        // this.jTextFieldCedula.setText("");
        this.jTextFieldTesoreroAuxiliar.setText("");
        this.jTextFieldSeguroSocial.setText("");
        this.jTextFieldOcupacion.setText("");
        //guara      this.jTextFieldNacionalidad.setText("");
        this.jTextFieldDomicilio.setText("");
        this.jTextFieldCasa.setText("");
        this.jTextFieldTelefono.setText("");
        this.jTextFieldApartado.setText("");
        this.jTextFieldEmail.setText("");
        this.jTextAreaObservacion.setText("");

        jButtonEliminar.setEnabled(false);
        jButtonActualizar.setEnabled(false);
        jButtonGuardar.setEnabled(false);
    }

    public void CargarTesoreroAuxiliar() {
        try {
            if (tesorerosAuxiliaresBeans.getActivo().equals("no")) {
                JOptionPane.showMessageDialog(this, "Este registro esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            this.jTextFieldCedula.setText(tesorerosAuxiliaresBeans.getCedula());
            sesion.setCedulaTesoreroAuxiliar(this.jTextFieldCedula.getText());
            this.jTextFieldTesoreroAuxiliar.setText(tesorerosAuxiliaresBeans.getTesoreroAuxiliar());

            jTextFieldSeguroSocial.setText(tesorerosAuxiliaresBeans.getIdSeguroSocial());
            jTextFieldOcupacion.setText(tesorerosAuxiliaresBeans.getOcupacion());
            jTextFieldNacionalidad.setText(tesorerosAuxiliaresBeans.getNacionalidad());
            jTextFieldDomicilio.setText(tesorerosAuxiliaresBeans.getDomicilio());
            jTextFieldCasa.setText(tesorerosAuxiliaresBeans.getCasa());
            jTextFieldTelefono.setText(tesorerosAuxiliaresBeans.getTelefono());
            jTextFieldApartado.setText(tesorerosAuxiliaresBeans.getApartadoPostal());
            jTextFieldEmail.setText(tesorerosAuxiliaresBeans.getEmail());
            jTextAreaObservacion.setText(tesorerosAuxiliaresBeans.getObservacion());

            //

            jComboBoxProvincia.setSelectedItem(tesorerosAuxiliaresBeans.getProvinciaVive());

            String corregimiento = BuscarCorregimientosCodigo(tesorerosAuxiliaresBeans.getIdMunicipio(), tesorerosAuxiliaresBeans.getIdCorregimiento());
            jComboBoxCorregimiento.setSelectedItem(corregimiento);


            CargarCorregimientos(tesorerosAuxiliaresBeans.getIdMunicipioVive(), false);

            String corregimientoVive = BuscarCorregimientosCodigo(tesorerosAuxiliaresBeans.getIdMunicipioVive(), tesorerosAuxiliaresBeans.getIdCorregimientoVive());
            jComboBoxCorregimientoVive.setSelectedItem(corregimientoVive);
            String municipioVive = sesion.BuscarMunicipiosCodigo(tesorerosAuxiliaresBeans.getIdMunicipioVive());
            jComboBoxMunicipioVive.setSelectedItem(municipioVive);
            jButtonGuardar.setEnabled(false);
            jButtonEliminar.setEnabled(false);
            jButtonActualizar.setEnabled(false);
            if (menuTesorerosAuxiliares.isBjMenuItemTesorerosAuxiliaresActualizar() == true) {
                jButtonActualizar.setEnabled(true);
            }
            if (menuTesorerosAuxiliares.isBjMenuItemTesorerosAuxiliaresEliminar() == true) {
                jButtonEliminar.setEnabled(true);
            }

            repaint();


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void CargarProvincias() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sqlquery = "select idprovincia, provincia  from provinces order by provincia";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            ResultSet rs = psquery.executeQuery();
            jComboBoxProvincia.removeAllItems();
            int count = 0;
            while (rs.next()) {
                String provincia = rs.getString("provincia");
                jComboBoxProvincia.insertItemAt(provincia, count);

                count++;
            }
            if (count != 0) {
                jComboBoxProvincia.setSelectedItem(1);
            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando provincias" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private String BuscarProvincias(String provincia) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return "";
            }

            String sqlquery = "select * from provinces where provincia = ? ";
            PreparedStatement psquery = sesion.con.prepareStatement(sqlquery);
            psquery.setString(1, provincia);

            ResultSet rs = psquery.executeQuery();
            rs.next();
            int x = rs.getRow();

            if (x == 0) {
                JOptionPane.showMessageDialog(this, "no existe una provincia con  ese nombre", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                sesion.con.close();
                return "";
            }

            return rs.getString("idprovincia");


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando Provincias" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        return "";
    }

    public void CargarMunicipios(String idProvincia, boolean comboCorregimientoActual) {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            PreparedStatement psquery;
            if (idProvincia.equals("")) {
                //cuando se quiere mostrar todos los corregimientos
                String sqlquery = "select idmunicipio, municipio from municipies ";
                psquery = sesion.con.prepareStatement(sqlquery);

            } else {
                String sqlquery = "select idmunicipio, municipio  from municipies where idprovincia = ?";
                psquery = sesion.con.prepareStatement(sqlquery);
                psquery.setString(1, idProvincia);
            }
            ResultSet rs = psquery.executeQuery();

            jComboBoxMunicipioVive.removeAllItems();


            int count = 0;
            while (rs.next()) {
                String municipio = rs.getString("municipio");
                jComboBoxMunicipioVive.insertItemAt(municipio, count);

                count++;
            }
            if (count != 0) {
                jComboBoxMunicipioVive.setSelectedIndex(0);
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error Cargando Corregimientos" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonActualizar;
    private javax.swing.JButton jButtonBuscarTesorerosAuxiliares;
    private javax.swing.JButton jButtonEliminar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonLimpiar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JComboBox jComboBoxCorregimiento;
    private javax.swing.JComboBox jComboBoxCorregimientoVive;
    private javax.swing.JComboBox jComboBoxMunicipioVive;
    private javax.swing.JComboBox jComboBoxProvincia;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextAreaObservacion;
    private javax.swing.JTextField jTextFieldApartado;
    private javax.swing.JTextField jTextFieldCasa;
    private javax.swing.JTextField jTextFieldCedula;
    private javax.swing.JTextField jTextFieldDomicilio;
    private javax.swing.JTextField jTextFieldEmail;
    private javax.swing.JTextField jTextFieldNacionalidad;
    private javax.swing.JTextField jTextFieldOcupacion;
    private javax.swing.JTextField jTextFieldSeguroSocial;
    private javax.swing.JTextField jTextFieldTelefono;
    private javax.swing.JTextField jTextFieldTesoreroAuxiliar;
    // End of variables declaration//GEN-END:variables
}
